import { axios } from '@/service/service'
import { ListReq, menuFormReq } from './types'

export function getMenuList(
  params: ListReq,
  page: number,
  pageSize: number
): any {
  return axios({
    url: '/system/menu/listTreeData',
    method: 'post',
    data: { ...params, page, pageSize },
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function getMenuListAll(): any {
  return axios({
    url: '/system/menu/listAll',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function createMenu(params: menuFormReq): any {
  return axios({
    url: '/system/menu/add',
    method: 'post',
    data: { ...params },
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function editMenu(params: menuFormReq): any {
  return axios({
    url: '/system/menu/edit',
    method: 'post',
    data: { ...params },
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function deleteMenu(ids: number, status: number): any {
  return axios({
    url: '/system/menu/remove',
    method: 'post',
    data: { ids: ids, status: status == 0 ? 1 : 0 },
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}
